package com.wanchuang.qhbb.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;


import com.wanchuang.qhbb.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件名 : ImageNumberView
 * 创建者 : MangoWang
 * 创建日期 : 2019/6/13 15:30
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : 将字符串转变成为图片数字
 */
public class ImageNumberView extends FrameLayout {

    private int len = 0;

    private ImageView number_ge;
    private ImageView number_shi;
    private ImageView number_bai;
    private ImageView number_qian;
    private ImageView number_wan;
    private ImageView number_shi_wan;
    private ImageView number_bai_wan;
    private ImageView number_qian_wan;
    private ImageView number_yi;
    private ImageView number_shi_yi;
    private ImageView number_bai_yi;
    private ImageView number_point_one;
    private ImageView number_point_two;
    private ImageView number_point;
    private List<ImageView> numberList = new ArrayList<>();


    public ImageNumberView(Context context) {
        super(context);
    }

    public ImageNumberView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        View.inflate(context, R.layout.image_number, this);
        number_ge = findViewById(R.id.number_ge);
        number_shi = findViewById(R.id.number_shi);
        number_bai = findViewById(R.id.number_bai);
        number_qian = findViewById(R.id.number_qian);
        number_wan = findViewById(R.id.number_wan);
        number_shi_wan = findViewById(R.id.number_shi_wan);
        number_bai_wan = findViewById(R.id.number_bai_wan);
        number_qian_wan = findViewById(R.id.number_qian_wan);
        number_yi = findViewById(R.id.number_yi);
        number_shi_yi = findViewById(R.id.number_shi_yi);
        number_bai_yi = findViewById(R.id.number_bai_yi);
        number_point_one = findViewById(R.id.number_point_one);
        number_point_two = findViewById(R.id.number_point_two);
        number_point = findViewById(R.id.number_point);


        numberList.add(number_bai_yi);
        numberList.add(number_shi_yi);
        numberList.add(number_yi);
        numberList.add(number_qian_wan);
        numberList.add(number_bai_wan);
        numberList.add(number_shi_wan);
        numberList.add(number_wan);
        numberList.add(number_qian);
        numberList.add(number_bai);
        numberList.add(number_shi);
        numberList.add(number_ge);
        numberList.add(number_point);
        numberList.add(number_point_one);
        numberList.add(number_point_two);
    }


    public void analyLanString(String numberString) {
        // 判断支付串是否为空
        if (TextUtils.isEmpty(numberString)) {
            Log.e("error", "analyString: ");
            return;
        }
        // 去除非数字的字符
        if (numberString.length() > 14) {
            numberString = numberString.substring(0, 14);
        }
        // 将String 转位Char类型数组
        int resId; // 默认资源id
        char[] numberC = numberString.toCharArray();
        for (int i = numberC.length - 1; i >= 0; i--) {
            switch (numberC[i]) {
                case '1':
                    resId = R.mipmap.lan_1;
                    break;
                case '2':
                    resId = R.mipmap.lan_2;
                    break;
                case '3':
                    resId = R.mipmap.lan_3;
                    break;
                case '4':
                    resId = R.mipmap.lan_4;
                    break;
                case '5':
                    resId = R.mipmap.lan_5;
                    break;
                case '6':
                    resId = R.mipmap.lan_6;
                    break;
                case '7':
                    resId = R.mipmap.lan_7;
                    break;
                case '8':
                    resId = R.mipmap.lan_8;
                    break;
                case '9':
                    resId = R.mipmap.lan_9;
                    break;
                case '0':
                    resId = R.mipmap.lan_0;
                    break;
                case '.':
                    resId = R.mipmap.lan_dian;
                    break;
                default:
                    resId = R.mipmap.lan_dou;
            }
            numberList.get(i).setImageResource(resId);
            numberList.get(i).setVisibility(VISIBLE);
        }
        if (len > numberC.length) {
            for (int i = numberC.length; i < len; i++) {
//                numberList.get(i).setImageResource(R.drawable.tran_bg);
                numberList.get(i).setVisibility(GONE);
            }
        }
        len = numberC.length;
    }
    public void analyLuString(String numberString) {
        // 判断支付串是否为空
        if (TextUtils.isEmpty(numberString)) {
            Log.e("error", "analyString: ");
            return;
        }
        // 去除非数字的字符
        if (numberString.length() > 14) {
            numberString = numberString.substring(0, 14);
        }
        // 将String 转位Char类型数组
        int resId; // 默认资源id
        char[] numberC = numberString.toCharArray();
        for (int i = numberC.length - 1; i >= 0; i--) {
            switch (numberC[i]) {
                case '1':
                    resId = R.mipmap.lu_1;
                    break;
                case '2':
                    resId = R.mipmap.lu_2;
                    break;
                case '3':
                    resId = R.mipmap.lu_3;
                    break;
                case '4':
                    resId = R.mipmap.lu_4;
                    break;
                case '5':
                    resId = R.mipmap.lu_5;
                    break;
                case '6':
                    resId = R.mipmap.lu_6;
                    break;
                case '7':
                    resId = R.mipmap.lu_7;
                    break;
                case '8':
                    resId = R.mipmap.lu_8;
                    break;
                case '9':
                    resId = R.mipmap.lu_9;
                    break;
                case '0':
                    resId = R.mipmap.lu_0;
                    break;
                case '.':
                    resId = R.mipmap.lu_dian;
                    break;
                default:
                    resId = R.mipmap.lu_dou;
            }
            numberList.get(i).setImageResource(resId);
            numberList.get(i).setVisibility(VISIBLE);
        }
        if (len > numberC.length) {
            for (int i = numberC.length; i < len; i++) {
//                numberList.get(i).setImageResource(R.drawable.tran_bg);
                numberList.get(i).setVisibility(GONE);
            }
        }
        len = numberC.length;
    }

    public void analyYouString(String numberString) {
        // 判断支付串是否为空
        if (TextUtils.isEmpty(numberString)) {
            Log.e("error", "analyString: ");
            return;
        }
        // 去除非数字的字符
        if (numberString.length() > 14) {
            numberString = numberString.substring(0, 14);
        }
        // 将String 转位Char类型数组
        int resId; // 默认资源id
        char[] numberC = numberString.toCharArray();
        for (int i = numberC.length - 1; i >= 0; i--) {
            switch (numberC[i]) {
                case '1':
                    resId = R.mipmap.you_1;
                    break;
                case '2':
                    resId = R.mipmap.you_2;
                    break;
                case '3':
                    resId = R.mipmap.you_3;
                    break;
                case '4':
                    resId = R.mipmap.you_4;
                    break;
                case '5':
                    resId = R.mipmap.you_5;
                    break;
                case '6':
                    resId = R.mipmap.you_6;
                    break;
                case '7':
                    resId = R.mipmap.you_7;
                    break;
                case '8':
                    resId = R.mipmap.you_8;
                    break;
                case '9':
                    resId = R.mipmap.you_9;
                    break;
                case '0':
                    resId = R.mipmap.you_0;
                    break;
                case '.':
                    resId = R.mipmap.you_dian;
                    break;
                default:
                    resId = R.mipmap.you_dou;
            }
            numberList.get(i).setImageResource(resId);
            numberList.get(i).setVisibility(VISIBLE);
        }
        if (len > numberC.length) {
            for (int i = numberC.length; i < len; i++) {
//                numberList.get(i).setImageResource(R.drawable.tran_bg);
                numberList.get(i).setVisibility(GONE);
            }
        }
        len = numberC.length;
    }


}


